<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Target Structure (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Target Structure (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Target Structure (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Target-Macros.html" rel="up" title="Target Macros">
<link href="Driver.html" rel="next" title="Driver">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Target-Structure">
<div class="nav-panel">
<p>
Next: <a href="Driver.html" accesskey="n" rel="next">Controlling the Compilation Driver, <samp class="file">gcc</samp></a>, Up: <a href="Target-Macros.html" accesskey="u" rel="up">Target Description Macros and Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="The-Global-targetm-Variable"><span>18.1 The Global <code class="code">targetm</code> Variable<a class="copiable-link" href="#The-Global-targetm-Variable"> &para;</a></span></h3>
<a class="index-entry-id" id="index-target-hooks"></a>
<a class="index-entry-id" id="index-target-functions"></a>

<dl class="first-deftypevr first-deftypevar-alias-first-deftypevr">
<dt class="deftypevr deftypevar-alias-deftypevr" id="index-targetm"><span class="category-def">Variable: </span><span><code class="def-type">struct gcc_target</code> <strong class="def-name">targetm</strong><a class="copiable-link" href="#index-targetm"> &para;</a></span></dt>
<dd><p>The target <samp class="file">.c</samp> file must define the global <code class="code">targetm</code> variable
which contains pointers to functions and data relating to the target
machine.  The variable is declared in <samp class="file">target.h</samp>;
<samp class="file">target-def.h</samp> defines the macro <code class="code">TARGET_INITIALIZER</code> which is
used to initialize the variable, and macros for the default initializers
for elements of the structure.  The <samp class="file">.c</samp> file should override those
macros for which the default definition is inappropriate.  For example:
</p><div class="example smallexample">
<pre class="example-preformatted">#include &quot;target.h&quot;
#include &quot;target-def.h&quot;

/* <span class="r">Initialize the GCC target structure.</span>  */

#undef TARGET_COMP_TYPE_ATTRIBUTES
#define TARGET_COMP_TYPE_ATTRIBUTES <var class="var">machine</var>_comp_type_attributes

struct gcc_target targetm = TARGET_INITIALIZER;
</pre></div>
</dd></dl>

<p>Where a macro should be defined in the <samp class="file">.c</samp> file in this manner to
form part of the <code class="code">targetm</code> structure, it is documented below as a
&ldquo;Target Hook&rdquo; with a prototype.  Many macros will change in future
from being defined in the <samp class="file">.h</samp> file to being part of the
<code class="code">targetm</code> structure.
</p>
<p>Similarly, there is a <code class="code">targetcm</code> variable for hooks that are
specific to front ends for C-family languages, documented as &ldquo;C
Target Hook&rdquo;.  This is declared in <samp class="file">c-family/c-target.h</samp>, the
initializer <code class="code">TARGETCM_INITIALIZER</code> in
<samp class="file">c-family/c-target-def.h</samp>.  If targets initialize <code class="code">targetcm</code>
themselves, they should set <code class="code">target_has_targetcm=yes</code> in
<samp class="file">config.gcc</samp>; otherwise a default definition is used.
</p>
<p>Similarly, there is a <code class="code">targetm_common</code> variable for hooks that
are shared between the compiler driver and the compilers proper,
documented as &ldquo;Common Target Hook&rdquo;.  This is declared in
<samp class="file">common/common-target.h</samp>, the initializer
<code class="code">TARGETM_COMMON_INITIALIZER</code> in
<samp class="file">common/common-target-def.h</samp>.  If targets initialize
<code class="code">targetm_common</code> themselves, they should set
<code class="code">target_has_targetm_common=yes</code> in <samp class="file">config.gcc</samp>; otherwise a
default definition is used.
</p>
<p>Similarly, there is a <code class="code">targetdm</code> variable for hooks that are
specific to the D language front end, documented as &ldquo;D Target Hook&rdquo;.
This is declared in <samp class="file">d/d-target.h</samp>, the initializer
<code class="code">TARGETDM_INITIALIZER</code> in <samp class="file">d/d-target-def.h</samp>.  If targets
initialize <code class="code">targetdm</code> themselves, they should set
<code class="code">target_has_targetdm=yes</code> in <samp class="file">config.gcc</samp>; otherwise a default
definition is used.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Driver.html">Controlling the Compilation Driver, <samp class="file">gcc</samp></a>, Up: <a href="Target-Macros.html">Target Description Macros and Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
